//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.Text;

namespace OpenLS.Spreadsheet
{
    static class StringEnumerable
    {
        public static string Concat<TSource> (IEnumerable<TSource> source, string separator)
        {
            bool first = true;
            var sb = new StringBuilder();
            foreach (var enumerable in source)
            {
                if (!first)
                    sb.Append(separator);
                sb.Append(enumerable);
                first = false;
            }
            return sb.ToString();
        }
        public static string Concat<TSource>(IEnumerable<TSource> source, Func<TSource, string> selector, string separator)
        {
            bool first = true;
            var sb = new StringBuilder();
            foreach (var enumerable in source)
            {
                if (!first)
                    sb.Append(separator);
                sb.Append(selector(enumerable));
                first = false;
            }
            return sb.ToString();
        }
        public static string Concat<TSource>(IEnumerable<TSource> source, Func<TSource, string> selector, char separator)
        {
            bool first = true;
            var sb = new StringBuilder();
            foreach (var enumerable in source)
            {
                if (!first)
                    sb.Append(separator);
                sb.Append(selector(enumerable));
                first = false;
            }
            return sb.ToString();
        }
    }
}